package com.yunjie.service.user;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.yunjie.dao.user.UserDao;
import com.yunjie.model.UserInfo;
@Service("userService")
@Transactional
public class UserServiceImpl implements UserService {
	@Autowired
	private UserDao userDao;
	
	@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
	public UserInfo login(UserInfo user) throws Exception {
		// TODO Auto-generated method stub
		List<UserInfo> list = userDao.findByLoginNameAndPassword(user.getLoginName(), user.getPassword());
		if(list.size() == 0){
			return null;
		}
		return list.get(0);
	}

	@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
	public UserInfo saveAndUpdata(UserInfo user) throws Exception {
		// TODO Auto-generated method stub
		UserInfo u = userDao.save(user);
		return u;
	}

	@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
	public void delete(Integer... ids) throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
	public List<UserInfo> findAll(Integer pageNow, Integer pageSize)
			throws Exception {
		// TODO Auto-generated method stub
		return (List<UserInfo>) userDao.findAll();
	}

	@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
	public UserInfo findById(Integer id) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

}
